<?php
{% include 'header.tpl' %}
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

?>

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script>
		var input=parent.document.getElementById("jform_<?php echo JRequest::getVar('idMap') ?>");
		input.value

		var center = new google.maps.LatLng(59.32522, 18.07002);
		var marker;
		var map;

		function initialize() {
			var mapOptions = {
			  zoom: 13,
			  mapTypeId: google.maps.MapTypeId.ROADMAP,
			  center: center
		};

        map = new google.maps.Map(document.getElementById('map_canvas'),
                mapOptions);

        marker = new google.maps.Marker({
		map:map,
		draggable: true,
		animation: google.maps.Animation.DROP,
		position: center
        });
        google.maps.event.addListener(marker, 'click', toggleBounce);
      }

      function toggleBounce() {

        if (marker.getAnimation() != null) {
          marker.setAnimation(null);
        } else {
          marker.setAnimation(google.maps.Animation.BOUNCE);
        }
      }
      
      function close()
      {
      	input=parent.document.getElementById("jform_<?php echo JRequest::getVar('idMap')?>");
      	input.value=marker.getPosition().lat()+", "+marker.getPosition().lng();
      }
      
	google.maps.event.addDomListener(window, 'load', initialize); 
	google.maps.event.addDomListener(window, 'unload', close);
	
    </script>

<div id="map_canvas" style="height: 400px;"></div>
